#include <iostream>

#include "SDL/SDL.h"
#include "SDL/SDL_image.h"

#include "SALT_Engine.h"
#include "SALT_Surface.h"
#include "SALT_ObjectContainer.h"
#include "SALT_Events.h"

using namespace std;

SALT::Objects::SurfaceObject* obj=NULL;

void die(){
	SALT::Engine::Quit();
}

int cb(void* data){
	SDL_Event* ev=(SDL_Event*)data;
	switch(ev->type){
		case SDL_KEYUP:
			if(ev->key.keysym.sym==SDLK_ESCAPE){
				die();
				break;
			}
			if(ev->key.keysym.sym==SDLK_LEFT)
				obj->position()[0]--;
			else if(ev->key.keysym.sym==SDLK_RIGHT)
				obj->position()[0]++;
			else if(ev->key.keysym.sym==SDLK_UP)
				obj->position()[1]--;
			else if(ev->key.keysym.sym==SDLK_DOWN)
				obj->position()[1]++;
			cout<<"keyup"<<endl;
			break;
	}
	return 0;
}

int main(int argc,char* argv[]){
	SALT::Events::SDLEventManager* ev=new SALT::Events::SDLEventManager();
	ev->registerCallback(SDL_KEYUP,cb);
	SALT::Graphics::SDLGraphicsManager* gm=new SALT::Graphics::SDLGraphicsManager(800,600,32,SDL_HWSURFACE|SDL_DOUBLEBUF);
	gm->eventManager()=ev;
	SALT::Engine::Init(gm);
	SALT::Objects::DrawableContainer* dc=new SALT::Objects::DrawableContainer();
	obj=new SALT::Objects::SurfaceObject();
	{
		SDL_Surface* surf=IMG_Load("logo_vec.png");
		obj->surf()=surf;
	}
	dc->addObject(obj);
	obj->position()[0]=10;
	obj->position()[1]=10;
	dc->position()[0]=-10;
	dc->position()[1]=-10;
	SALT::Engine::AddObject((SALT::Objects::Object*)dc);
	SALT::Engine::Run();
	SALT::Engine::Quit();
	return 0;
}
